/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Parser;

import lowlevel.Function;
import lowlevel.Operand;
import lowlevel.Operation;

/**
 *
 * @author maxmuhlenkamp
 */
public class NumExpression extends Expression{
    int value;
    
    public NumExpression(int value){
        this.value = value;
    }

    @Override
    void print(String indent) {
        CMinusParser.oFile.println(indent + "NumExpression");
        CMinusParser.oFile.println(indent + "  " + value);
        CMinusParser.oFile.flush();
    }

    @Override
    public void genLLCode(Function func) {
        // assign a register number
        regNum = func.getNewRegNum();
        
        // create a move operation to put the value in the register
        Operation move = new Operation(Operation.OperationType.ASSIGN, func.getCurrBlock());
        Operand dest0 = new Operand(Operand.OperandType.REGISTER, regNum);
        Operand src0 = new Operand(Operand.OperandType.INTEGER, value);
        
        move.setSrcOperand(0, src0);
        move.setDestOperand(0, dest0);
        func.getCurrBlock().appendOper(move);
    }
}
